﻿// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Reflection;

namespace System.ComponentModel.Composition.ReflectionModel
{
    internal class ReflectionField : ReflectionWritableMember
    {
        private readonly FieldInfo _field;

        public ReflectionField(FieldInfo field)
            : base(field)
        {
            _field = field;
        }

        public override bool CanRead
        {
            get { return true; }
        }

        public override bool CanWrite
        {
            get { return !_field.IsInitOnly; }
        }

        public override bool RequiresInstance
        {
            get { return !_field.IsStatic; }
        }

        public override Type ReturnType
        {
            get { return _field.FieldType; }
        }

        public override object GetValue(object instance)
        {
            return _field.GetValue(instance);
        }

        public override void SetValue(object instance, object value)
        {
            _field.SetValue(instance, value);
        }
    }
}
